package com.ItemsRent.action;

import java.util.HashMap;
import java.util.List;

import com.ItemsRent.IService.service.ItemTypeImpl;
import com.ItemsRent.model.ItemType;
import com.ItemsRent.IService.*;


public class ItemTypeAction {
	
	private ItemType ithType;
	private IitemType ithTypeService ;
	private String itemTypeName;
	private Integer itemTypeId;
	private String PtypeName;
	private HashMap<String, Object> result=new HashMap<String, Object>();
	
	public ItemType getIthType() {
		return ithType;
	}

	public void setIthType(ItemType ithType) {
		this.ithType = ithType;
	}

	public IitemType getIthTypeService() {
		return ithTypeService;
	}

	public void setIthTypeService(IitemType ithTypeService) {
		this.ithTypeService = ithTypeService;
	}

	public String getItemTypeName() {
		return itemTypeName;
	}

	public void setItemTypeName(String itemTypeName) {
		this.itemTypeName = itemTypeName;
	}

	public Integer getItemTypeId() {
		return itemTypeId;
	}

	public void setItemTypeId(Integer itemTypeId) {
		this.itemTypeId = itemTypeId;
	}

	public String getPtypeName() {
		return PtypeName;
	}

	public void setPtypeName(String ptypeName) {
		PtypeName = ptypeName;
	}

	public HashMap<String, Object> getResult() {
		return result;
	}

	public void setResult(HashMap<String, Object> result) {
		this.result = result;
	}

	/**
	 * 添加物品种类
	 */
	public void addItemType(){
		this.ithTypeService.insert(this.ithType);
	}
	
	/**
	 * 删除物品种类
	 */
	public void deleteItemTable(){
		this.ithType=this.ithTypeService.findByType_Id(this.itemTypeId);
		this.ithTypeService.delete(this.ithType);
	}
	
	/**
	 * 根据物品种类ID查找物品种类 
	 */
	public String FindItemTypeByTypeId(){
		this.ithType=this.ithTypeService.findByType_Id(this.itemTypeId);
		System.out.println(this.ithType.toString());
		result.put("itemType", this.ithType);
		return "success";
	}
	
	/**
	 * 根据物品种类名称查找物品种类 
	 */
	public String FindItemTypeByName(){
		List<ItemType> list =this.ithTypeService.findByItemType_Name(this.itemTypeName);
		for(ItemType item : list){
			System.out.println(item.toString());
		}
		result.put("itemTypes", list);
		return "success";
	}
	
	/**
	 * 根据物品种类名称查找物品种类 (返回一个对象)
	 */
	public ItemType FindOneItemTypeByName(String itemTypeName){
		List<ItemType> list =this.ithTypeService.findByItemType_Name(itemTypeName);
		for(ItemType item : list){
			System.out.println(item.toString());
		}
		return list.get(0);
	}
	
	/**
	 * 根据物品父类ID查找物品种类 
	 */
	public String FindItemTypeByPtype(){
		List<ItemType> list =this.ithTypeService.findByPtype(this.PtypeName);
		/*
		for(ItemType item : list){
			System.out.println(item.toString());
		}
		*/
		result.put("itemTypes", list);
		return "success";
	}
	
	/**
	 * 返回数据库里面的所有物品种类 
	 */
	public String showall(){
		List<ItemType> list = ithTypeService.findAll();
		//System.out.println(this.itemTypeName);
		//List<ItemType> list = ithTypeService.findByItemType_Name(this.itemTypeName);
		//List<ItemType> list = ithTypeService.findByPtype(Ptype);
	/*
		ItemType it = ithTypeService.findByType_Id(this.itemTypeId);
		System.out.println(it.toStirng());
	*/
		
		//System.out.println("Running to Line 50");
		result.put("itemTypes", list);
		for(ItemType item : list){
			System.out.println(item.toString());
		}
		
		return "success";
	}
	
	/*
	public static void main(String args[]){
		ItemTypeAction itemTypeAction = new ItemTypeAction();
		itemTypeAction.ithTypeService=new ItemTypeImpl();
		//itemTypeAction.setItemTypeName("ujhew");
		itemTypeAction.showall();
	}
	*/
}
